home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 040a / crr0150a.zip / CRRTIM.Z < prev    next >
Text File  |  1993-03-20  |  6KB  |  337 lines

  1. ; CRR Time overlay (c) 1993 Paul Martin
  2. ; ================
  3. ;
  4. ; This is the standard overlay which works for both standard CP/M 2.2
  5. ; and CP/M 3.1 (Plus)
  6. ;
  7. ; Under CP/M 3.1 the time is obtained using BDOS function 105.
  8. ; Under CP/M 2.2 the time is "fudged"
  9. ;
  10. ; This file should be assembled using Dave Goodenough's ZSM23,
  11. ;
  12. ;    ZSM CRRTIM
  13. ;
  14. ; and applied to CRR using his ZPATCH
  15. ;
  16. ;    ZPATCH CRR CRRTIM
  17. ;
  18. ;
  19. .org    0x2100
  20.  
  21. entry:
  22.     jp    gettad
  23.  
  24. ; table starts at 0x2103
  25.  
  26. year:    dw    0    ; Year
  27. month:    db    0    ; Month 1=Jan, 2=Feb, .. 12=Dec
  28. day:    db    0    ; Day of month
  29. dow:    db    0    ; Day of week 1=Sun, 2=Mon,.., 7=Sat
  30. hour:    db    0    ; Hour in 24h format 0=midnight, 13=1pm
  31. mins:    db    0    ; Minute
  32. secs:    db    0    ; Second (if supported, zero otherwise)
  33. rtc:    db    0    ; non-zero if rtc present
  34.  
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;;;;;;;;;;  DO NOT CHANGE ANYTHING ABOVE THIS LINE  ;;;;;;;;;;;;
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38. ;
  39. ; The space 0x2100 to 0x22ff (512 bytes) has been set aside for
  40. ; real time clock overlays.
  41. ;
  42. ; You may freely modify this overlay for use as a CRR time
  43. ; overlay. The single condition of its use is that if you modify
  44. ; it, you should make public your modifications so that other
  45. ; people with similar equipment may be able to use it.
  46. ;
  47. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  48.  
  49.  
  50. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  51. ; Jul2Day
  52. ;  - Day of year -> year,month,day converter
  53. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  54. jul2day:
  55. ;
  56. ; Entry:
  57. ;  HL = Day of year
  58. ;  BC = Year
  59. ; Exit:
  60. ;  E = Month
  61. ;  D = Day
  62. ;  BC = Year
  63. ;       all other registers and flags preserved
  64. ;
  65.         push    af      ; save registers
  66.     push    ix
  67.     push    hl
  68.     push    bc
  69.  
  70.     ld    de,1    ; month = 1
  71.     ld    ix,dayinmo
  72. jullp:  ld      b,(ix)  ; how many days in this month
  73.     ld    a,e
  74.     cp    2
  75.         jr      nz,jntlp ; not February
  76.     ld    a,c
  77.     and    3
  78.         jr      nz,jntlp ; not leap year
  79.         inc     b       ; 29 days in Feb in leap yr
  80. jntlp:
  81.     ld    a,l
  82.     sub    b
  83.     ld    l,a
  84.         jr      c,jcarry   ; b>l
  85.         or      a
  86.         jr      z,jcarry  ; b=l
  87.  
  88. jncrry: inc     e       ; next month
  89.     inc    ix
  90.     jr    jullp
  91.  
  92. jcarry: inc     h
  93.         dec     h
  94.         jr      z,jfin
  95.         dec     h
  96.         jr      jncrry
  97.  
  98. jfin:   ld      a,l
  99.     add    a,b
  100.     ld    d,a
  101.     pop    bc
  102.     pop    hl
  103.     pop    ix
  104.     pop    af
  105.     ret
  106.  
  107. dayinmo:    ; data for jul2day
  108.     db    31,28,31,30,31,30,31,31,30,31,30,31
  109.  
  110.  
  111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  112. ; BCD2Bin
  113. ; - BCD to Binary converter
  114. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  115. bcd2bin:
  116. ;
  117. ; Entry:
  118. ;   A = BCD number
  119. ; Exit:
  120. ;   A = binary number
  121. ; flags corrupted
  122. ;   
  123.     push    bc
  124.     ld    b,a    ;save a
  125.     and    0xf0    ; mask off lower bits
  126.     srl    a    ;x8
  127.     ld    c,a    ; store a*8
  128.     srl    a    ;x4
  129.     srl    a    ;x2
  130.     add    a,c    ;x2 + x8 = x10
  131.     ld    c,a
  132.     ld    a,b
  133.     and    0x0f
  134.     add    a,c
  135.     pop    bc
  136.     ret
  137.  
  138.  
  139. ;;;;;;;;;;
  140. ; CPM2Jul
  141. ;  CPMDate (days since Jan 1 1978) -> year, dayofyear
  142. ;;;;;;;;;;
  143. cpm2jul:
  144. ;
  145. ;
  146. ; Entry:
  147. ;  HL = CPMdate
  148. ; Exit:
  149. ;  BC = year
  150. ;  HL = dayofyear
  151. ;  all other registers and flags preserved
  152. ;
  153.     push    af
  154.     push    de
  155.     ld    de,1978        ; Base year = 1978
  156. c2jl:    ld    bc,365        ; yearlen = 365 days
  157.     ld    a,e        ; is leap year?
  158.     and    3
  159.     jr    nz,c2j1
  160.     inc    bc        ; Yes, year = 366 days
  161.     and    a        ; clear carry
  162. c2j1:    sbc    hl,bc        ; cpmdate -= yearlen.
  163.     jr    c,c2j2
  164.     inc    de        ; not this year
  165.     jr    c2jl        ; go round again
  166. c2j2:    add    hl,bc        ; restore days
  167.     ld    b,d
  168.     ld    c,e
  169.     pop    de
  170.     pop    af
  171.     ret            ; get out
  172.  
  173.  
  174. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  175. ; Zeller
  176. ;  -  Zeller's congruence for dates later than 1978
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178. zeller:
  179. ;
  180. ; Entry conditions:
  181. ;  year, month and day contain legal values
  182. ;
  183. ; Exit:
  184. ;  dow is set correctly
  185. ;
  186. ;  all registers and flags preserved
  187. ;
  188.     push    af
  189.     push    hl
  190.     push    de
  191.     push    bc
  192.     ld    bc,(year)
  193.     ld    de,(month)
  194.  
  195.     push    bc    ; save for later
  196.     push    de    ; ditto
  197.     ld    h,b
  198.     ld    l,c    ; HL = year
  199.  
  200.     push    hl
  201.     ld    bc,1978
  202.     or    a
  203.     sbc    hl,bc    ; HL = year - 1978
  204.     ex    (sp),hl    ; (SP) = year-1978,   HL=year
  205.  
  206.     ld    bc,1976
  207.     or    a
  208.     sbc    hl,bc    ; HL=year-1976
  209.     srl    h
  210.     rr    l    ; div 2
  211.     srl    h
  212.     rr    l    ; div 4
  213.     ex    de,hl
  214.     pop    hl    ; HL = (year-78), DE=(year-76)div 4
  215.     add    hl,de    ; HL = HL+DE
  216.  
  217.     pop    de    ; D = day, E = month
  218.     push    de    ; save again
  219.  
  220.     push    hl    ; save this, too
  221.     ld    hl,monmod
  222.     dec    e
  223.     ld    d,0
  224.     add    hl,de
  225.     ld    e,(hl)    ; table lookup, de = month correction
  226.     pop    hl
  227.     add    hl,de    ; add correction
  228.  
  229.     pop    de    ; D/E=day/month
  230.     ld    c,d
  231.     ld    b,0    ; BC = day
  232.     add    hl,bc    ; HL = accum+day
  233.     dec    hl
  234.  
  235.     pop    bc    ; BC = year
  236.     ld    a,c
  237.     and    3
  238.     jr    nz,zncorr    ; not a leap year
  239.     ld    a,e
  240.     cp    3
  241.     jr    nc,zncorr    ; March or later
  242.     dec    hl        ; take off a day
  243.  
  244. zncorr:            ; Using repeated subtraction for space, not speed
  245.     ld    bc,7    ; mod 7
  246.     or    a    ; clear carry
  247. znl:    sbc    hl,bc    ; subtract
  248.     jr    nc,znl    ; until carry
  249.  
  250.     add    hl,bc    ; add it back on
  251.     ld    a,l    ; a = day(0-6)
  252.     inc     a    ; (1-7)
  253.     ld    (dow),a
  254.     pop    bc
  255.     pop    de    ; restore registers
  256.     pop    hl
  257.     pop    af
  258.     ret
  259.  
  260. monmod:        ;data for zeller
  261.     db    0,3,3,6,1,4,6,2,5,0,3,5
  262.     
  263.  
  264. .var    bdos    0x0005    ; a handy definition
  265.  
  266. ;;;;;;;;;;;;;;;;;;;;;;;;
  267. ; This routine gets called by CRR
  268. ;;;;
  269. gettad:
  270. ;
  271. ; Entry:
  272. ;  no special conditions
  273. ;
  274. ; Exit:
  275. ;  year, month, day, dow, hour, mins, secs, and rtc
  276. ;    should contain valid information.
  277. ;
  278. ; AF,BC,DE,HL may be changed on return
  279. ; Suggest IX,IY be unchanged (unsure)
  280. ;
  281. ;
  282.     ld    c,12
  283.     call    bdos    ; get CP/M version number.
  284.     ld    a,l
  285.     cp    0x31    ; are we running under CP/M Plus?
  286.     jr    nc,cpmplus
  287.     call    zeller
  288.     xor    a
  289.     ld    (rtc),a    ; Under this environment, there is no RTC
  290.     ld    hl,mins
  291.     inc    (hl)    ; bump minutes
  292.     ld    a,59
  293.     cp    (hl)
  294.     ret    nc    ; mins less than or equal to 59
  295.     ld    (hl),0    ; mins = 0
  296.     dec    hl    ; point to hour
  297.     inc    (hl)    ; bump hour
  298.     ld    a,23
  299.     cp    (hl)
  300.     ret    nc    ; hour is less than or equal to 23
  301.     ld    (hl),23    ; can't be bothered with days
  302.     inc    hl
  303.     inc    hl
  304.     inc    (hl)    ; bump seconds, so that MSGIDs are OK
  305.     ret
  306. cpmplus:
  307.     ld    c,105
  308.     ld    de,datrec
  309.     call    bdos
  310.     call    bcd2bin
  311.     ld    (secs),a
  312.     ld    a,(datmn)
  313.     call    bcd2bin
  314.     ld    (mins),a
  315.     ld    a,(dathr)
  316.     call    bcd2bin
  317.     ld    (hour),a
  318.     ld    hl,(datint)
  319.     call    cpm2jul
  320.     call    jul2day
  321.     ld    (year),bc
  322.     ld    (month),de    ; this sets day as well
  323.     call    zeller
  324.     ld    a,1
  325.     ld    (rtc),a
  326.     ret
  327. ;
  328.  
  329.     
  330.  
  331. datrec:        ; CP/M time record
  332. datint:    dw    0
  333. dathr:    db    0
  334. datmn:    db    0
  335.  
  336.  
  337.